package com.seaboxdata.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seaboxdata.dao.HdfsDao;
import com.seaboxdata.dao.HiveDataDao;
import com.seaboxdata.dao.HiveDataInfoDao;
import com.seaboxdata.entity.HiveDataInfo;
import com.seaboxdata.entity.TableConfig;
import com.seaboxdata.service.HiveDataInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Date;
import java.util.List;

/**
 * @author
 * @create 2020-12-29 11:57
 **/
@Service("hiveDataInfoService")
@Slf4j
public class HiveDataInfoServiceImpl extends ServiceImpl<HiveDataInfoDao, HiveDataInfo> implements HiveDataInfoService {

    @Autowired
    private HiveDataDao hiveDao;

    @Autowired
    private HdfsDao hdfsDao;

    @Autowired
    private HiveDataInfoDao hiveDataInfoDao;

    @Override
    public HiveDataInfo getDataInfo(TableConfig tableConfig) {
        return hiveDao.getDataInfo(tableConfig);
    }

    @Override
    public long getTotalCount(Date date) {
        long totalCount = 0;
        List<HiveDataInfo> hiveDataInfos = hiveDataInfoDao.getTodayHiveDataInfo(date);
        for (HiveDataInfo hiveDataInfo : hiveDataInfos) {
            int dataSize = ObjectUtils.isEmpty(hiveDataInfo.getDataSize()) ? 0 : hiveDataInfo.getDataSize();
            totalCount += dataSize;
        }
        return totalCount;
//        return totalCount / 10000;
    }

    @Override
    public Integer getTotalIncrement(Date date) {
        int totalCount = 0;
        List<HiveDataInfo> hiveDataInfos = hiveDataInfoDao.getTodayHiveDataInfo(date);
        for (HiveDataInfo hiveDataInfo : hiveDataInfos) {
            int dataSizeInc = ObjectUtils.isEmpty(hiveDataInfo.getDataSizeIncrement())?0:hiveDataInfo.getDataSizeIncrement();
            totalCount += dataSizeInc;
        }
        return totalCount / 10000;
    }

}
